package com.panda.cn.controller;

import cn.hutool.json.JSONObject;
import com.panda.cn.entity.SysUserEntity;
import com.panda.cn.service.SysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping(value = "/login")
public class LoginController {
    
    @Resource
    private SysUserService sysUserService;
    
    /**
     * 登录
     *
     * @return {@link List}
     */
    @RequestMapping(value = "", method = RequestMethod.POST)
    public String login(@RequestBody JSONObject params, HttpServletRequest request) {
        return sysUserService.login(params, request);
    }
    /**
     * 获取用户信息
     *
     * @return {@link List}
     */
    @RequestMapping(value = "/userinfo", method = RequestMethod.GET)
    public SysUserEntity userinfo(HttpServletRequest request) {
        String token = request.getHeader("token");
        return sysUserService.userinfo(token);
    }
}
